잠시만 기다려 주세요

     '이태원 핼러윈 참사.. 150명 넘게 죽었는데 눈치나 보며 아무것도 안 하는 민주당을 규탄한다. 총선 보이콧... 문재인 시즌2 는 절대 금지다...'
전체검색 :  
이번주 로또 및 연금번호 발생!!   |  HOME   |  여기는?   |  바다물때표   |  알림 (16)  |  여러가지 팁 (1054)  |  추천 및 재미 (150)  |  자료실 (22)  |  
시사, 이슈, 칼럼, 평론, 비평 (582)  |  끄적거림 (127)  |  문예 창작 (702)  |  바람 따라 (69)  |  시나리오 (760)  |  드라마 대본 (248)  |  
살인!


    golang

golang - 문자열 포맷, String Formatting
이 름 : 바다아이   |   조회수 : 6940         짧은 주소 : https://www.bada-ie.com/su/?221591785070
// Go offers excellent support for string formatting in
// the `printf` tradition. Here are some examples of
// common string formatting tasks.

package main

import (
	"fmt"
	"os"
)

type point struct {
	x, y int
}

func main() {

	// Go offers several printing "verbs" designed to
	// format general Go values. For example, this prints
	// an instance of our `point` struct.
	p := point{1, 2}
	fmt.Printf("%v\n", p)

	// If the value is a struct, the `%+v` variant will
	// include the struct's field names.
	fmt.Printf("%+v\n", p)

	// The `%#v` variant prints a Go syntax representation
	// of the value, i.e. the source code snippet that
	// would produce that value.
	fmt.Printf("%#v\n", p)

	// To print the type of a value, use `%T`.
	fmt.Printf("%T\n", p)

	// Formatting booleans is straight-forward.
	fmt.Printf("%t\n", true)

	// There are many options for formatting integers.
	// Use `%d` for standard, base-10 formatting.
	fmt.Printf("%d\n", 123)

	// This prints a binary representation.
	fmt.Printf("%b\n", 14)

	// This prints the character corresponding to the
	// given integer.
	fmt.Printf("%c\n", 33)

	// `%x` provides hex encoding.
	fmt.Printf("%x\n", 456)

	// There are also several formatting options for
	// floats. For basic decimal formatting use `%f`.
	fmt.Printf("%f\n", 78.9)

	// `%e` and `%E` format the float in (slightly
	// different versions of) scientific notation.
	fmt.Printf("%e\n", 123400000.0)
	fmt.Printf("%E\n", 123400000.0)

	// For basic string printing use `%s`.
	fmt.Printf("%s\n", "\"string\"")

	// To double-quote strings as in Go source, use `%q`.
	fmt.Printf("%q\n", "\"string\"")

	// As with integers seen earlier, `%x` renders
	// the string in base-16, with two output characters
	// per byte of input.
	fmt.Printf("%x\n", "hex this")

	// To print a representation of a pointer, use `%p`.
	fmt.Printf("%p\n", &p)

	// When formatting numbers you will often want to
	// control the width and precision of the resulting
	// figure. To specify the width of an integer, use a
	// number after the `%` in the verb. By default the
	// result will be right-justified and padded with
	// spaces.
	fmt.Printf("|%6d|%6d|\n", 12, 345)

	// You can also specify the width of printed floats,
	// though usually you'll also want to restrict the
	// decimal precision at the same time with the
	// width.precision syntax.
	fmt.Printf("|%6.2f|%6.2f|\n", 1.2, 3.45)

	// To left-justify, use the `-` flag.
	fmt.Printf("|%-6.2f|%-6.2f|\n", 1.2, 3.45)

	// You may also want to control width when formatting
	// strings, especially to ensure that they align in
	// table-like output. For basic right-justified width.
	fmt.Printf("|%6s|%6s|\n", "foo", "b")

	// To left-justify use the `-` flag as with numbers.
	fmt.Printf("|%-6s|%-6s|\n", "foo", "b")

	// So far we've seen `Printf`, which prints the
	// formatted string to `os.Stdout`. `Sprintf` formats
	// and returns a string without printing it anywhere.
	s := fmt.Sprintf("a %s", "string")
	fmt.Println(s)

	// You can format+print to `io.Writers` other than
	// `os.Stdout` using `Fprintf`.
	fmt.Fprintf(os.Stderr, "an %s\n", "error")
}



결과



{1 2}
{x:1 y:2}
main.point{x:1, y:2}
main.point
true
123
1110
!
1c8
78.900000
1.234000e+08
1.234000E+08
"string"
"\"string\""
6865782074686973
0xc00002c040
|    12|   345|
|  1.20|  3.45|
|1.20  |3.45  |
|   foo|     b|
|foo   |b     |
a string
an error



출처 : https://gobyexample.com/string-formatting

| |





      1 page / 6 page
번 호 카테고리 제 목 이름 조회수
179 golang golang , ... 바다아이 1308
178 golang golang , map . 바다아이 1043
177 golang Golang (, , data ) , ... 바다아이 1047
176 golang golang sort ... 바다아이 1217
175 golang golang html.EscapeString html.UnescapeString input value ... 바다아이 1387
174 golang golang go.mod go.sum . GOPATH SRC not module, 1.16 . 바다아이 4530
173 golang go 1.16 ... is not in GOROOT.. GOPATH .... . 바다아이 5364
현재글 golang , String Formatting 바다아이 6941
171 golang rand.Intn , random, , . 바다아이 6527
170 golang golang ... 바다아이 9277
169 golang golang gopath, goroot .. golang 바다아이 7112
168 golang golang ... Force download file example 바다아이 8874
167 golang golang , , cpu, memory, disk 바다아이 10161
166 golang golang , ... GOOS, GOARCH 바다아이 8048
165 golang golang checkbox ... 바다아이 7760
164 golang golang , , http .... 바다아이 7577
163 golang golang nil , nil , nil ... 바다아이 7843
162 golang 2 golang, go , .... golang .... 바다아이 10637
161 golang golang postgresql, mysql, mariadb ... ` Grave () .. .. 바다아이 8099
160 golang golang postgresql mysql, mariadb scan , null .. 바다아이 8199
159 golang golang , iconv 바다아이 10992
158 golang golang quote escape, unquote 바다아이 8366
157 golang golang , http errorLog , , ... 바다아이 8483
156 golang golang interface , 바다아이 7988
155 golang golang struct .... 바다아이 8658
154 golang golang map map , 바다아이 8224
153 golang golang map .... .... 바다아이 7744
152 golang golang slice copy 바다아이 7835
151 golang golang goto 바다아이 8673
150 golang golang slice sort , int, string, float64 바다아이 8104
| |









Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Ubuntu + GoLang + PostgreSQL + Mariadb ]
서버위치 : 오라클 클라우드 춘천  실행시간 : 0.05608
to webmaster... gogo sea. gogo sea.